/**
 *  Copyright (c)  2011-2020 Panguso, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Panguso, 
 *  Inc. ("Confidential Information"). You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into with Panguso.
 */

package cn.edu.thu.log.util;

import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
 * 
 * @author Student
 *
 */
public final class Emails {
	
private Emails() {
		super();
	}

/**
 * 
 * @param from parameter
 * @param to parameter
 * @param subject parameter
 * @param messageText parameter
 * @param password parameter
 * @return
 */
	public static boolean emailExecute(String from, String to, String subject,
			String messageText, String password) {
		boolean bool = true;
		try {
			String mailserver = "smtp.qq.com";
			Properties props = new Properties();
			props.put("mail.smtp.host", mailserver);
			props.put("mail.smtp.auth", "true");
			Session sess = Session.getInstance(props);
			sess.setDebug(true);
			MimeMessage message = new MimeMessage(sess);

			InternetAddress frommail = new InternetAddress(from);
			message.setFrom(frommail);

			InternetAddress tomeil = new InternetAddress(to);
			message.setRecipient(Message.RecipientType.TO, tomeil);
			message.setSubject(subject);
			message.setText(messageText);
			message.setSentDate(new Date());

			message.saveChanges();
			Transport transport = sess.getTransport("smtp");
			transport.connect(mailserver, from, password);
			transport.sendMessage(message, message.getAllRecipients());
			transport.close();

			bool = true; // �ʼ����ͳɹ��� ����true
		} catch (Exception e) {
			e.printStackTrace();
			bool = false; // �ʼ�����ʧ���� ����false

		}
		return bool;
	}

}
